import 'package:flutter/material.dart';
import 'package:flutter_demo/demo/basic_demo.dart';
import 'package:flutter_demo/demo/bloc/bloc_demo.dart';
import 'package:flutter_demo/demo/demo_bottom_navigation_bar.dart';
import 'package:flutter_demo/demo/demo_drawer.dart';
import 'package:flutter_demo/demo/form_demo.dart';
import 'package:flutter_demo/demo/http/http_demo.dart';
import 'package:flutter_demo/demo/i18n/i18n_demo.dart';
import 'package:flutter_demo/demo/layout_demo.dart';
import 'package:flutter_demo/demo/materialCompinents.dart';
import 'package:flutter_demo/demo/navigator_demo.dart';
import 'package:flutter_demo/demo/sliver_demo.dart';
import 'package:flutter_demo/demo/test/test_demo.dart';
import 'package:flutter_demo/demo/view_demo.dart';
import '../demo/demo_listview.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_demo/demo/i18n/map/languageLocalizations.dart';

import 'demo/animation/animation_demo.dart';
import 'demo/rxdart/rxdart_demo.dart';
import 'demo/state/state_managenment_demo.dart';
import 'demo/stream/stream_demo.dart';

void main() {
  runApp(const App());
}

class App extends StatelessWidget {
  const App({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        //多语言 start
        // locale: Locale('en','US'), //指定当前语言英语
        locale: Locale('zh','CN'), ////指定当前语言中文
        // localeResolutionCallback:(locale, supportedLocales) { //监听系统语言切换
        //   return const Locale('en','US');
        // },
        localizationsDelegates: [
          LanguageLocationDelegate(),
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
        ],
        supportedLocales: const [
          Locale('en', 'US'),
          Locale('zh', 'CN')
        ],
        //多语言 end
        debugShowCheckedModeBanner: false, //关闭右上角 debug
        theme: ThemeData(
            primarySwatch: Colors.yellow, //主题颜色
            highlightColor: Color.fromRGBO(255, 255, 255, 0.5), //高亮颜色
            splashColor: Colors.white70, //水波纹颜色
            primaryColor: Color.fromRGBO(3, 54, 255, 1.0) 
            ),
        // home: Home(), // 跟initialRoute 保留一个
        initialRoute: '/',
        routes: {
          '/':(context) => Home(),
          '/about': (context) => Page(title: 'about'),
          '/form':(context) => FormDemo(),
          '/mdc' :(context) => MaterialCompinents(),
          '/i18n' :(context) => I18nDemo(),
          '/test' :(context) => TestDemo(),
          '/animation' :(context) => AnimationDemo(),
          '/http' :(context) => HttpDemo(),
          '/bloc' :(context) => BlocDemo(),
          '/rxdart' :(context) => RxDartDemo(),
          '/state' :(context) => StateManagementDemo(),
          '/stream' :(context) => StreamDemo(),
        },
        );
  }
}

class Home extends StatefulWidget {
  Home({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => HomeWidegetState();
}

class HomeWidegetState extends State<Home> {
  int _tabIndex = 0;
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 5,
      child: Scaffold(
          backgroundColor: Colors.grey[100],
          appBar: AppBar(
              title: const Text('NINGHAO'),
              elevation: 1.0,
              // leading: IconButton(onPressed: ()=> debugPrint('navigation button is pressed'), icon: Icon(Icons.menu)),
              actions: [
                IconButton(
                    onPressed: () => debugPrint('search button is pressed'),
                    icon: Icon(Icons.search)),
                IconButton(
                    onPressed: () => debugPrint('more button is pressed'),
                    icon: Icon(Icons.more_horiz)),
              ],
              bottom: const TabBar(
                unselectedLabelColor: Colors.black38,
                indicatorColor: Colors.black54,
                indicatorSize: TabBarIndicatorSize.label,
                indicatorWeight: 1.0,
                tabs: <Widget>[
                  Tab(icon: Icon(Icons.local_florist)),
                  Tab(icon: Icon(Icons.local_hospital)),
                  Tab(icon: Icon(Icons.directions_bike)),
                  Tab(icon: Icon(Icons.view_quilt)),
                  Tab(icon: Icon(Icons.view_kanban)),
                ],
              )),
          body: [
            TabBarView(
              children: <Widget>[
                DemoListView(),
                BasicDemo(),
                // Icon(Icons.local_hospital,size: 128.0, color: Colors.black12),
                // Icon(Icons.directions_bike,size: 128.0, color: Colors.black12),
                LayoutDemo(),
                ViewDemo(),
                SliverDemo()
              ],
            ),
            NavigatorDemo()
          ][_tabIndex],
          drawer: const DemoDrawer(),
          bottomNavigationBar: DemoBottomNavigationBar(
              currentIndex: _tabIndex,
              onTap: (value) {
                setState(() {
                  _tabIndex = value;
                });
              })),
    );
  }
}


class Page extends StatelessWidget{
  final String? title;
  
  Page({
    this.title
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title??''),
        elevation: 0.0,
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.arrow_back),
        onPressed: (){
          Navigator.pop(context);
        },
      ),


    );
  }

}